/* 
 * This trigger prevents the deletion of any opportunity that
 * has an associated quote
 */
trigger oppTrigger on Opportunity (before delete) {
	/* Trigger.oldMap is a trigger context variable that maps Ids to every
	   opportunity that is about to be deleted. Use it in a SOQL query to
	   create a list of associated quotes. */
	for (Quote__c q : [select opportunity__c from quote__c 
	                   where opportunity__c in :Trigger.oldMap.keySet()]) {
		/* For every quote that is active, retrieve the related opportunity
	       from Trigger.oldMap and prevent it from being deleted by placing
	       an error message on the opportunity. */
		Trigger.oldMap.get(q.opportunity__c).addError(
		'Cannot delete opportunity with a quote');
	}
}